Repository navigation
[kotlin][client] Support useJackson3 for the jvm-ktor library - #25639
Open
denysgaievskyi wants to merge 2 commits into
Open
denysgaievskyi wants to merge 2 commits into
denysgaievskyi wants to merge 2 commits into
Conversation
The jvm-ktor templates hard-coded Jackson 2 (com.fasterxml.jackson) in ApiClient and the API classes, and the codegen rejected useJackson3 for this library. This follows the approach of OpenAPITools#24709 for jvm-okhttp4 and jvm-spring-restclient: - allow useJackson3 with library jvm-ktor - ApiClient/api templates: with useJackson3, import tools.jackson and io.ktor.serialization.jackson3, and take jsonBlock as JsonMapper.Builder.() -> Unit (Jackson 3 mappers are immutable and configured through a builder). JavaTimeModule is dropped: java.time support is built into Jackson 3 databind. - build.gradle: with useJackson3, depend on ktor-serialization-jackson3 instead of ktor-client-jackson and ktor-serialization-jackson. - new sample kotlin-jvm-ktor-jackson3, added to the Kotlin client samples workflow. - tests for the Jackson 3 output and for the unchanged Jackson 2 default. Without useJackson3 the generated code is unchanged.
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 54 files
Reply to a comment to ask cubic a question or push back. It learns from your replies.
View guided diff | Re-trigger cubic
AndreyVMarkelov
left a comment
Contributor
There was a problem hiding this comment.
The tests and sample build pass, but Jackson 3 fails at runtime on Java 11. Could we use Java 17 for this sample and add a simple JSON serialization/deserialization test? CI currently skips tests with -x test.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This extends the approach of #24709 (Jackson 3 for
jvm-okhttp4andjvm-spring-restclient) to thejvm-ktorlibrary.Today the codegen rejects
useJackson3forjvm-ktor, and thejvm-ktortemplates hard-code Jackson 2 (com.fasterxml.jackson) inApiClientand in the API classes.Changes:
KotlinClientCodegen: allowuseJackson3withlibrary=jvm-ktor.jvm-ktor/infrastructure/ApiClient.kt.mustacheandjvm-ktor/api.mustache: withuseJackson3, the generated code importstools.jacksonandio.ktor.serialization.jackson3, andjsonBlockbecomesJsonMapper.Builder.() -> Unit. Jackson 3 mappers are immutable and configured through a builder, so the parameter type changes.JavaTimeModuleis not registered, because Jackson 3 databind supportsjava.timeitself.build.gradle.mustache: withuseJackson3,jvm-ktordepends onktor-serialization-jackson3instead ofktor-client-jacksonandktor-serialization-jackson.samples/client/petstore/kotlin-jvm-ktor-jackson3, added to the Kotlin client samples workflow.Without
useJackson3, the generated code does not change.Note for users who switch: the Jackson 2
JSON_DEFAULTwritesOffsetDateTimeas an epoch number, becauseWRITE_DATES_AS_TIMESTAMPSis on by default in Jackson 2. Jackson 3 writes ISO-8601 strings by default, which matchesformat: date-time.Tested:
KotlinClientCodegenModelTestandKotlinClientCodegenApiTest: 111 tests, 0 failures../bin/generate-samples.sh bin/configs/kotlin*(130 configs): the only output change is the new sample../bin/utils/export_docs_generators.sh: no change../gradlew build -x testin the new sample: passes.Notes on the automated review:
docs/is identical to the existingkotlin-jvm-ktor-jacksonsample (diff -ris empty). The doc-example issues come from the shared jvm-ktor docs templates, which this PR does not change.kotlin-jackson3andkotlin-jvm-spring-4-restclient-jackson3. The CI step compiles only (./gradlew build -x test), and those samples pass there on master. I can move all three to a Java 17 entry if you prefer.PR checklist
./mvnw install -DskipTestsplus the Kotlin codegen tests above, and regenerated only the Kotlin samples (bin/configs/kotlin*), because only Kotlin templates changed:cc @karismann @Zomzog @andrewemery @4brunu @yutaka0m @stefankoppier @e5l @AndreyVMarkelov